package com.gt.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gt.common.annotation.Log;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.enums.BusinessType;
import com.gt.admin.domain.FlowConfig;
import com.gt.admin.domain.apiVO.FlowConfigVVO;
import com.gt.admin.service.IFlowConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 随访配置controller
 */
@Api(tags = "sc-随访配置")
@RestController
@RequestMapping("/flow-config")
public class FlowConfigController extends BaseController {
    @Autowired
    private IFlowConfigService flowConfigService;

    /**
     * 查询随访配置列表
     */
    @ApiOperation("查询随访配置列表")
    @GetMapping
    public AjaxResult list(FlowConfig flowConfig){
        LambdaQueryWrapper<FlowConfig> queryWrapper = new LambdaQueryWrapper<>(flowConfig);
        List<FlowConfig> flowConfigList = flowConfigService.list(queryWrapper);
        return AjaxResult.success(flowConfigList);
    }

    /**
     * 根据superid查询版本
     */
    @ApiOperation("根据superid查询版本")
    @GetMapping("/version/{superid}")
    public AjaxResult selectVersion(@PathVariable("superid")Long superid){
        return AjaxResult.success(flowConfigService.selectVersion(superid));
    }

    /**
     * 根据superid查询随访配置及明细
     */
    @ApiOperation("根据superid查询随访配置及明细")
    @GetMapping("/{superid}")
    public AjaxResult selectById(@PathVariable("superid")Long superid){
        return AjaxResult.success(flowConfigService.selectBySuperId(superid));
    }

    /**
     * 新增或修改随访配置，更新生效版本
     */
    @ApiOperation("新增或修改随访配置")
    @Log(title = "随访配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(@RequestBody FlowConfigVVO flowConfigVVO){
        return toAjax(flowConfigService.update(flowConfigVVO));
    }

    /**
     * 删除随访配置
     */
    @ApiOperation("删除随访配置")
    @Log(title = "随访配置",businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id")Long id){
        return toAjax(flowConfigService.deleteById(id));
    }
}
